﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace InstitutionAssitant
{
    /// <summary>
    /// ClassName:UserInfo
    /// Version:1.0
    /// Date:2017-3-31
    /// Author:SeanOuyang
    /// </summary>
    /// <remarks>
    /// 本类是实体类UserInfo(操作员信息)属性说明类
    /// </remarks>
    public class UserInfo
    {
        #region 1.属性
        //序号
        public int m_nID { set; get; }
        //用户编号
        public string m_strCode { set; get; }
        //用户姓名
        public string m_strName { set; get; }
        //登录口令
        public string m_strPassword { set; get; }
        //用户编号
        public string m_strDeptCode { set; get; }
        //用户编号
        public string m_strDeptName { set; get; }
        #endregion

        /// <summary>
        /// 构造函数(值初始化)
        /// </summary>
        public UserInfo()
        {
            m_nID = 0;
            m_strCode = "";
            m_strName = "";
            m_strPassword = "";
            m_strDeptCode = "";
            m_strDeptName = "";
        }

        /// <summary>
        /// 身份校验
        /// </summary>
        public Boolean _checkLogin()
        {
            Boolean bReturn = false;
            string strSql = "select * from T_Base_User where Status = 1 and Code = '{0}' and Password = '{1}'";
            strSql = string.Format(strSql, m_strCode.Replace("'", "''"), m_strPassword.Replace("'", "''"));
            DataTable dt = DbHelper.DBAccess[0]._openSql_Dt(strSql);
            bReturn = (dt != null) && (dt.Rows.Count > 0);
            if (bReturn)
            {
                m_nID = CommDll.FunctionComm._strToInt(dt.Rows[0]["ID"].ToString());
                m_strName = dt.Rows[0]["Name"].ToString();
                m_strCode= dt.Rows[0]["Code"].ToString();
                m_strDeptCode = dt.Rows[0]["InstitutionCode"].ToString();
                m_strDeptName = dt.Rows[0]["InstitutionName"].ToString();
            }           
            return bReturn;
        }

        /// <summary>
        /// 更改口令
        /// </summary>
        public Boolean _changePassword(string strPasswordNew)
        {
            Boolean bReturn = false;
            string strSql = "Update T_Base_User set Password = '{1}' where ID = {0}";
            strSql = string.Format(strSql, m_nID, strPasswordNew.Replace("'", "''"));
            bReturn = DbHelper.DBAccess[0]._execSql(strSql) > 0;            
            return bReturn;
        }
    }
}
